package com.prothink.controller;

import com.prothink.entity.UserCoupon;
import com.prothink.service.UserCouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description：优惠券列表
 * @author     ：wangchong
 * @date       ：2022/11/12 14:23
 */
@Slf4j
@Controller
@RequestMapping("/coupon")
public class UserCouponController {

    @Autowired
    private UserCouponService userCouponService;

    /**
     * @author: wangchong
     * @description: TODO
     * @date: 2022/11/12 14:23
     * @params: []
     * @return: java.util.List<com.prothink.entity.UserCoupon>
     */
    @CrossOrigin
    @ResponseBody
    @PostMapping("/getCoupon")
    public List<UserCoupon> getCoupon(){
        log.info("优惠券列表");
        List<UserCoupon> all = userCouponService.getAll();
        return all;
    }

    /**
     * @author: wangchong
     * @description: 根据操作的当前行优惠券ID，进行修改当前行优惠券状态
     * @date: 2022/11/12 16:44
     * @params: [online：优惠券上/下线状态, couponId：当前行优惠券ID]
     * @return: java.util.Map
     */
    @CrossOrigin
    @ResponseBody
    @PostMapping("/updateCoupon")
    public Map updateCoupon(Integer online,Integer couponId) {
        System.out.println("online:"+online+",cou:"+couponId);
        Map<String, Object> map = new HashMap<>();
        Boolean aBoolean = userCouponService.updateCoupon(online,couponId);
        map.put("start",aBoolean);
        return map;
    }

    /**
     * @author: wangchong
     * @description: 筛选优惠券，根据优惠券的名称、状态、发放方式查询
     * @date: 2022/11/13 11:20
     * @params: [couponName:优惠券名称, grant:发放方式, online：优惠券状态]
     * @return: com.prothink.entity.JsonResult
     */
    @CrossOrigin
    @ResponseBody
    @PostMapping("/getScreen")
    public List<UserCoupon> getScreen(String couponName, Integer grant, Integer online){
        System.out.println("couponName:"+couponName+",grant:"+grant+",online:"+online);
        List<UserCoupon> screen = userCouponService.getScreen(couponName, grant, online);
        return screen;
    }

    /**
     * @author: wangchong
     * @description: 根据ID删除数据
     * @date: 2022/11/14 18:50
     * @params: [couponId：删除当前行的ID]
     * @return: java.util.Map
     */
    @CrossOrigin
    @ResponseBody
    @PostMapping("/deleteCoupon")
    public Map deleteCoupon(Integer couponId) {
//        Boolean aBoolean = userCouponService.deleteCoupon(couponId);
        Map<String, Object> map = new HashMap<>();
        map.put("start",true);
        return map;
    }

    /**
     * @author: wangchong
     * @description: 添加优惠券
     * @date: 2022/12/13 18:50
     * @params: [userCoupon：添加的优惠券对象]
     * @return: java.util.Map
     */
    @CrossOrigin
    @ResponseBody
    @PostMapping("/addCoupon")
    public Map addCoupon(@RequestBody UserCoupon userCoupon) {
        System.out.println(userCoupon);
        Boolean aBoolean = userCouponService.addCoupon(userCoupon);
        System.out.println(aBoolean);
        Map<String, Object> map = new HashMap<>();
        map.put("start",aBoolean);
        return map;
    }

    /**
     * @author: wangchong
     * @description: 查看用户优惠券
     * @date: 2022/12/14 18:50
     * @return: all
     */
    @CrossOrigin
    @ResponseBody
    @PostMapping("/getCouponUser")
    public List<UserCoupon> getCouponUser() {
        log.info("用户拥有优惠券列表");
        List<UserCoupon> all = userCouponService.getCouponUser();
        return all;
    }


    /**
     * @author: wangchong
     * @description: 筛选查看优惠券用户，根据优惠券的名称查看用户
     * @date: 2022/12/15 11:20
     * @params: [couponName:优惠券名称, grant:发放方式, online：优惠券状态]
     * @return: com.prothink.entity.JsonResult
     */
    @CrossOrigin
    @ResponseBody
    @PostMapping("/getScreen2")
    public List<UserCoupon> getScreen2(String userAccount, String nickname){
        List<UserCoupon> screen = userCouponService.getScreen2(userAccount, nickname);
        return screen;
    }


    /**
     * @author: wangchong
     * @description: 优惠券明细，根据用户ID查询优惠券明细
     * @date: 2022/1/31 11:14
     * @params: []
     * @return:
     */
    @CrossOrigin
    @ResponseBody
    @GetMapping("/getCouponUserId")
    public List<UserCoupon> getCouponUserId(Integer userId) {
        List<UserCoupon> screen = userCouponService.getCouponUserId(userId);
        System.out.println(screen);
        return screen;
    }

    /**
    * @Description:
    * @Param: userId 所查看优惠券的用户ID
    * @return:
    * @Author: wangchong
    * @Date: 2023/2/1
    */
    @CrossOrigin
    @ResponseBody
    @GetMapping("/getCouponId2")
    public List<UserCoupon> getCouponId2(Integer userId){
        List<UserCoupon> screen = userCouponService.getCouponId2(userId);
        System.out.println(screen);
        return screen;
    }
}
